package me.pinion.controller;

import me.pinion.Log;
import me.pinion.controller.annotation.RouteBind;
import me.pinion.model.ModelType;
import me.pinion.model.User;
import me.pinion.model.Visit;
import me.pinion.model.XModel;

import javax.servlet.http.HttpServletResponse;

@RouteBind("/visit")
public class VisitController extends Controller{
    public void index(){

        String clazzStr = getPara("clazz");
        int targetId = getParaToInt("id");
        try {
            XModel model = ModelType.dao.getByClass(clazzStr).getModel(targetId);
            if (model == null){
                throw new NotFoundException();
            }
            Visit visit = Visit.dao.visit(model, this.<User>getSessionAttr("user"));
            renderJson(visit);
        } catch (Exception e) {
            Log.e(e);
            renderError(HttpServletResponse.SC_NOT_FOUND);
        }
    }
}
